<template>
  <div class="info">
    <div class="card_con">
      <div class="row mb15">
        <span class="l" @click="handleAdd">
          <i class="el-icon-circle-plus-outline"></i>新增
        </span>
      </div>
      <el-table
        border
        :data="tableData"
        :header-cell-style="{
          'text-align': 'center',
        }"
        :cell-style="{ 'text-align': 'center' }"
        style="width: 100%"
        highlight-current-row
      >
        <!-- <el-table-column type="selection" min-width="5%"> </el-table-column> -->
        <el-table-column prop="id" label="id" min-width="5%"> </el-table-column>

        <el-table-column prop="name" label="标题" min-width="20%">
        </el-table-column>
        <el-table-column label="图标" min-width="15%">
          <template slot-scope="scope">
            <div class="slt">
              <el-popover placement="right" width="200" trigger="hover">
                <img class="tbImg1" :src="scope.row.img" alt="" />
                <img
                  class="tbImg"
                  slot="reference"
                  :src="scope.row.img"
                  alt=""
                />
              </el-popover>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="sort" label="排序" min-width="20%">
        </el-table-column>
        <el-table-column prop="rout_uni" label="路由" min-width="20%">
        </el-table-column>
        <el-table-column prop="status" label="状态" min-width="10%">
          <template slot-scope="scope">
            <div class="green" v-if="scope.row.status === 0">启用</div>
            <div class="red" v-if="scope.row.status === 1">禁用</div>
            <!-- <el-switch
              @change="changeSwitch(scope.row)"
              class="tablescope"
              v-model="scope.row.status"
              active-text="禁用"
              inactive-text="启用"
              :active-value="0"
              :inactive-value="1"
              inactive-color=""
            >
            </el-switch> -->
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="20%">
          <template slot-scope="scope">
            <div class="caozuo">
              <div class="handleEdit hand_cs" @click="handleEdit(scope.row)">
                修改
              </div>
              <div
                class="handleDelete hand_cs"
                @click="handleDelete(scope.row)"
              >
                删除
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <Pagination
          :page="page"
          @onCurrentChange="handleCurrentChange"
          @onSizeChange="handleSizeChange"
        />
      </div>
    </div>
    <el-dialog :title="title" :visible.sync="Dialog" width="700px">
      <AddEdit
        v-if="Dialog"
        :rowData="rowData"
        @handleClose="handleClose"
      ></AddEdit>
    </el-dialog>
  </div>
</template>

<script>
import { indexNav } from "@/api/sale";
import AddEdit from "./addEditNav_dialog.vue";
import Pagination from "@/components/Pagination.vue";
import { doNav } from "@/api/sale";
export default {
  components: { Pagination, AddEdit },
  data() {
    return {
      shopKeeper: "",
      storeName: "",
      shopTypeId: 1,
      shopStateId: 1,
      time: "",
      page: {
        total: 0,
        pageNum: 1, // 当前页数
        pageSize: 10, // 每页的条数
      },
      shopState: [
        { id: 1, name: "启用" },
        { id: 2, name: "禁用" },
      ],
      shopType: [
        { id: 1, name: "入驻" },
        { id: 2, name: "自营" },
      ],

      tableData: [],
      title: "",
      Dialog: false,
      rowData: {},
    };
  },
  methods: {
    async indexNav() {
      const { data, err } = await indexNav({});
      if (err === 0) {
        this.tableData = data;
        this.page.total = data.length;
        this.page.pageSize = data.length;
      }
    },
    //删除接口
    //商品类型
    async doNav(id, action) {
      const { msg, err } = await doNav({
        id: id,
        action: action,
      });
      if (err === 0) {
        this.$message({
          type: "success",
          message: "删除成功!",
        });
        this.indexNav();
      } else {
        this.$message({
          message: msg,
          type: "error",
        });
      }
    },
    //删除
    handleDelete(row) {
      console.log(row);
      this.$confirm("是否确认删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.doNav(row.id, "DEL");
        })
        .catch(() => {});
    },
    //新增
    handleAdd() {
      this.title = "新增";
      this.Dialog = true;
      this.rowData = {};
    },
    handleClick(tab) {
      console.log(tab);
    },
    handleEdit(row) {
      this.title = "修改";
      this.Dialog = true;
      this.rowData = row;
    },
    // 每页 ${val} 条
    handleSizeChange(val) {
      //   this.$emit("onSizeChange", val);
    },
    // 当前页: ${val}
    handleCurrentChange(val) {
      //   this.$emit("onCurrentChange", val);
    },
    handleClose() {
      this.Dialog = false;
      this.indexNav();
    },
  },
  created() {
    this.indexNav();
  },
};
</script>

<style lang="scss" scoped>
@import "@/style/index.scss";

.info {
  .title {
    font-size: 16px;
    margin-bottom: 13px;
  }
}
.pagination {
  display: flex;
  justify-content: flex-end;
  padding-top: 10px;
}
.el-select {
  width: 100%;
}

.tb {
  background-color: #fff;
  padding: 20px;
  box-sizing: border-box;
}
.row {
  display: flex;
  border-radius: 2px;
  //   border: 1px solid #ccc;
  .l {
    padding: 8px 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #ccc;
    font-size: 13px;
    i {
      margin-right: 6px;
      font-size: 13px;
    }
    &:hover {
      cursor: pointer;
    }
  }
}
.caozuo {
  display: flex;
  justify-content: center;
  .handleDelete {
    margin-left: 20px;
  }
}
/deep/.el-dialog {
  height: 82%;
  .el-dialog__body {
    height: 70%;
    overflow: auto;
  }
}
</style>
